var app = getApp();
var util = require('../../../utils/util.js');

Page({
    data: {
        proId: "",  //产品id
        type: "",
        rule: "",
        shadowFlag: false,
        orderInfo: "",
        orderId:"",
        thumb:"",
        systemInfo:{},
        padBtm:"25",
    },
    onLoad: function (e) {
        var that = this;
        wx.getSystemInfo({
            success:function(res){ 
              if(res.model == "iPhone X"){
                that.setData({
                    padBtm:"50",
                })
              }
            }
        });
        that.setData({
            navH: app.globalData.navHeight,
            proId: e.id,
            type: e.type,
            thumb:e.thumb,
            orderInfo: e
        })
        that.getRule();
    },
    navBack: function () {
        wx.navigateBack({
            delta: 1
        })
    },
    getRule: function () {
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/house",
            data: {
                id: that.data.proId
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var ruleData = util.baseDecode(res.data.data.rule);
                    that.setData({
                        rule: ruleData,
                    })
                }
            },
            
        });
    },
    agreeOrder: function (e) {
        let formId = e.detail.formId;
        var that = this;
        that.setData({
            shadowFlag: true,
        })
        wx.request({
            url: app.globalData.apiHost + "/api/order/saveOrder",
            data: {
                goods_id: that.data.orderInfo.id,
                number: that.data.orderInfo.number,
                order_type: that.data.orderInfo.order_type,
                intime: that.data.orderInfo.intime,
                outtime: that.data.orderInfo.outtime,
                days: that.data.orderInfo.days,
                people_num: that.data.orderInfo.people_num,
                mobile:that.data.orderInfo.mobile,
                form_id: formId,
                email:that.data.orderInfo.email
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie':'token='+wx.getStorageSync('token')
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    that.setData({
                        shadowFlag: false,
                        orderId:res.data.data
                    })
                    wx.redirectTo({
                        url: '/pages/template/reserve/reserve?id=1&orderId='+that.data.orderId+'&thumb='+that.data.thumb
                    })
                }
            },
            
        });
    }
})

